package com.tt.dao;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.tt.bean.Message;
import com.tt.utils.GetResult;
@Repository
public class ChatMessageImpl implements ChatMessage {

	@Override
	public void sendMessage(Message msg) {
		SqlSession ss = null;
		try {
			ss = GetResult.getSqlSession();
			ss.insert("com.tt.bean.Message.insertMsg", msg);
			ss.commit();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			ss.close();
		}
	}

	@Override
	public List<Message> selectMessage(Message msg) {
		SqlSession ss = null;
		List list = null;
		try {
			ss = GetResult.getSqlSession();
			list = ss.selectList("com.tt.bean.Message.selectMsg",msg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			ss.close();
		}
		return list;
	}

	@Override
	public void updateMessageStatus(Message msg) {
		SqlSession ss = null;
		try {
			ss = GetResult.getSqlSession();
			ss.update("com.tt.bean.Message.updateMsg", msg);
			ss.commit();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			ss.close();
		}
		
	}

	@Override
	public List<Message> selectChatMsgList(Long id) {
		SqlSession ss = null;
		List list = null;
		HashMap<String, String> hm = new HashMap<>();
		hm.put("id","table"+id);
		try {
			ss = GetResult.getSqlSession();
			list = ss.selectList("com.tt.bean.Message.selectMsgList",hm);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			ss.close();
		}
		return list;
	}

}
